asp.net mvc - Server error: if (User.IsInRole("Administrators")) -
in mvc 4 internet application can't use this:
@if (user.isinrole("administrators"))
it result in error:
a network-related or instance-specific error occurred while establishing connection sql server. >server not found or not accessible. verify instance name correct , sql server >configured allow remote connections. (provider: sql network interfaces, error: 26 - error locating >server/instance specified)
this has been bothering me quite long time appreciated.
here stack trace:
[sqlexception (0x80131904): network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: sql network interfaces, error: 26 - error locating server/instance specified)] system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction) +5296071 system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose) +558 system.data.sqlclient.tdsparser.connect(serverinfo serverinfo, sqlinternalconnectiontds connhandler, boolean ignoresniopentimeout, int64 timerexpire, boolean encrypt, boolean trustservercert, boolean integratedsecurity, boolean withfailover) +5308555 system.data.sqlclient.sqlinternalconnectiontds.attemptonelogin(serverinfo serverinfo, string newpassword, securestring newsecurepassword, boolean ignoresniopentimeout, timeouttimer timeout, boolean withfailover) +145 system.data.sqlclient.sqlinternalconnectiontds.loginnofailover(serverinfo serverinfo, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance, sqlconnectionstring connectionoptions, sqlcredential credential, timeouttimer timeout) +920 system.data.sqlclient.sqlinternalconnectiontds.openloginenlist(timeouttimer timeout, sqlconnectionstring connectionoptions, sqlcredential credential, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance) +307 system.data.sqlclient.sqlinternalconnectiontds..ctor(dbconnectionpoolidentity identity, sqlconnectionstring connectionoptions, sqlcredential credential, object providerinfo, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance, sqlconnectionstring userconnectionoptions) +434 system.data.sqlclient.sqlconnectionfactory.createconnection(dbconnectionoptions options, dbconnectionpoolkey poolkey, object poolgroupproviderinfo, dbconnectionpool pool, dbconnection owningconnection, dbconnectionoptions useroptions) +5311099 system.data.providerbase.dbconnectionfactory.createpooledconnection(dbconnectionpool pool, dbconnectionoptions options, dbconnectionpoolkey poolkey, dbconnectionoptions useroptions) +37 system.data.providerbase.dbconnectionpool.createobject(dbconnectionoptions useroptions) +558 system.data.providerbase.dbconnectionpool.usercreaterequest(dbconnectionoptions useroptions) +67 system.data.providerbase.dbconnectionpool.trygetconnection(dbconnection owningobject, uint32 waitformultipleobjectstimeout, boolean allowcreate, boolean onlyonecheckconnection, dbconnectionoptions useroptions, dbconnectioninternal& connection) +1052 system.data.providerbase.dbconnectionpool.trygetconnection(dbconnection owningobject, taskcompletionsource`1 retry, dbconnectionoptions useroptions, dbconnectioninternal& connection) +78 system.data.providerbase.dbconnectionfactory.trygetconnection(dbconnection owningconnection, taskcompletionsource`1 retry, dbconnectionoptions useroptions, dbconnectioninternal& connection) +167 system.data.providerbase.dbconnectionclosed.tryopenconnection(dbconnection outerconnection, dbconnectionfactory connectionfactory, taskcompletionsource`1 retry, dbconnectionoptions useroptions) +143 system.data.sqlclient.sqlconnection.tryopen(taskcompletionsource`1 retry) +83 system.data.sqlclient.sqlconnection.open() +96 system.web.dataaccess.sqlconnectionholder.open(httpcontext context, boolean revertimpersonate) +88 system.web.dataaccess.sqlconnectionhelper.getconnection(string connectionstring, boolean revertimpersonation) +239 system.web.security.sqlroleprovider.getrolesforuser(string username) +762 webmatrix.webdata.simpleroleprovider.getrolesforuser(string username) +53 system.web.security.roleprincipal.isinrole(string role) +9461104 asp._page_views_home_index_cshtml.execute() in e:\hr\vorönn 2013\verk\bordspil\bordspil\views\home\index.cshtml:23 system.web.webpages.webpagebase.executepagehierarchy() +197 system.web.mvc.webviewpage.executepagehierarchy() +97 system.web.webpages.startpage.runpage() +17 system.web.webpages.startpage.executepagehierarchy() +62 system.web.webpages.webpagebase.executepagehierarchy(webpagecontext pagecontext, textwriter writer, webpagerenderingbase startpage) +76 system.web.mvc.razorview.renderview(viewcontext viewcontext, textwriter writer, object instance) +260 system.web.mvc.buildmanagercompiledview.render(viewcontext viewcontext, textwriter writer) +115 system.web.mvc.viewresultbase.executeresult(controllercontext context) +295 system.web.mvc.controlleractioninvoker.invokeactionresult(controllercontext controllercontext, actionresult actionresult) +13 system.web.mvc.<>c__displayclass1a.<invokeactionresultwithfilters>b__17() +23 system.web.mvc.controlleractioninvoker.invokeactionresultfilter(iresultfilter filter, resultexecutingcontext precontext, func`1 continuation) +242 system.web.mvc.<>c__displayclass1c.<invokeactionresultwithfilters>b__19() +21 system.web.mvc.controlleractioninvoker.invokeactionresultwithfilters(controllercontext controllercontext, ilist`1 filters, actionresult actionresult) +177 system.web.mvc.async.<>c__displayclass2a.<begininvokeaction>b__20() +89 system.web.mvc.async.<>c__displayclass25.<begininvokeaction>b__22(iasyncresult asyncresult) +102 system.web.mvc.async.wrappedasyncresult`1.end() +57 system.web.mvc.async.asynccontrolleractioninvoker.endinvokeaction(iasyncresult asyncresult) +43 system.web.mvc.<>c__displayclass1d.<beginexecutecore>b__18(iasyncresult asyncresult) +14 system.web.mvc.async.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult`1.end() +62 system.web.mvc.controller.endexecutecore(iasyncresult asyncresult) +57 system.web.mvc.async.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult`1.end() +62 system.web.mvc.controller.endexecute(iasyncresult asyncresult) +47 system.web.mvc.controller.system.web.mvc.async.iasynccontroller.endexecute(iasyncresult asyncresult) +10 system.web.mvc.<>c__displayclass8.<beginprocessrequest>b__3(iasyncresult asyncresult) +25 system.web.mvc.async.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult`1.end() +62 system.web.mvc.mvchandler.endprocessrequest(iasyncresult asyncresult) +47 system.web.mvc.mvchandler.system.web.ihttpasynchandler.endprocessrequest(iasyncresult result) +9 system.web.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() +9629296 system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +155
edit: results in error when auto login.
in mvc user.isinrole
or similar authorization methods trying use simplemembership provider default.
if using custom authorization need add below code web.config:
<system.webserver> <modules> <remove name="rolemanager" /> </modules> </system.webserver>
if using simplemembership make sure databases initialized.
Comments
Post a Comment