mvc中使用membership 权限 ( 安装和配置步骤)

第一步首先要安装membership对应数据库中的表



点击安装根据提示向下安装, 最后链接sql 选择自己对应的数据。


配置web.config文件

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
	<connectionStrings>
		<add name="ProjectDBContext" connectionString="Data Source=.;Initial Catalog=siaml;User ID=sa;password=123456;MultipleActiveResultSets=True"
		  providerName="System.Data.SqlClient" />
	
	</connectionStrings>
	<appSettings>
		<add key="webpages:Version" value="2.0.0.0" />
		<add key="webpages:Enabled" value="false" />
		<add key="PreserveLoginUrl" value="true" />
		<add key="ClientValidationEnabled" value="true" />
		<add key="UnobtrusiveJavaScriptEnabled" value="true" />
		<add key="Web.DefaultCulture" value="zh-CN" />
		<!-- memorycache or netcache -->
		<add key="Web.CacheName" value="" />
		<!-- rabbit or msmq -->
		<add key="Web.MqName" value="" />
	</appSettings>
	<system.web>
		<compilation debug="true" targetFramework="4.0" />
		//登陆权限 使用区域管理后台的权限
		<authentication mode="Forms">
			<forms name="Login" timeout="60"
				   loginUrl="Admin/Users/Login"
				   slidingExpiration="true"
				   cookieless="AutoDetect"
				   protection="All"
				   requireSSL="false"
				   enableCrossAppRedirects="false"
				   defaultUrl="Admin/Home/Index"
				   path="/"/>
		</authentication>


		<membership defaultProvider="ProjectProvider" userIsOnlineTimeWindow="5">
			<providers>
				<clear/>
				<add name="ProjectProvider"
					 connectionStringName="ProjectDBContext" //数据库名称
					 applicationName="Project" //解决方案名称
					 enablePasswordRetrieval="false"
					 enablePasswordReset="true"
					 requiresQuestionAndAnswer="false"
					 requiresUniqueEmail="false"
					 passwordFormat="Hashed" 
					 minRequiredPasswordLength="3"
					 minRequiredNonalphanumericCharacters="0"
					 type="System.Web.Security.SqlMembershipProvider"/>
			</providers>
			
		</membership>
		//允许访问除去配置以外的文件
		<authorization>
			<allow users="*"/>
		</authorization>
		 
	       //角色权限  applicationName //程序集名称
	  	<roleManager enabled="true" defaultProvider="ProjectProvider">
			<providers>
				<clear/>
				<add name="ProjectProvider"
					 connectionStringName="ProjectDBContext" 
					 applicationName="Project"  
					 type="System.Web.Security.SqlRoleProvider"/>
			</providers>
		</roleManager>
	   <!-- //表示任何用户都要验证 -->
		<!--<authorization>
      <allow users="*"/>
    </authorization>-->
		
		<pages>
			<namespaces>
				<add namespace="System.Web.Helpers" />
				<add namespace="System.Web.Mvc" />
				<add namespace="System.Web.Mvc.Ajax" />
				<add namespace="System.Web.Mvc.Html" />
				<add namespace="System.Web.Routing" />
				<add namespace="System.Web.WebPages" />
			</namespaces>
		</pages>
	</system.web>
	<system.webServer>
		<validation validateIntegratedModeConfiguration="false" />
		<modules runAllManagedModulesForAllRequests="true" />
		<handlers>
			<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
			<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
			<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
			<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
			<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
			<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
		</handlers>
	</system.webServer>


       //添加方法让用户能页面和方法  不进行merbership的验证
	<location path="home/adduserall">
		<system.web>
			<authorization>
				<allow users="*"/>
			</authorization>
		</system.web>
	</location>
</configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值