【发布时间】:2014-12-15 22:36:53
【问题描述】:
我的 MVC 网站在 web.config 中有一个表单授权。 现在所有页面都需要通过授权才能查看。
但是现在我有一个控制台程序(C# 控制台程序)。这个程序需要发送一些消息到 SignalR 集线器。 但是我的 signalR Hub 在我的 MVC 网站中,现在这个 C# 控制台客户端无法向 Signal Hub 发送消息, 因为我的 MVC 网站有表单授权。
我希望控制台客户端不需要验证,但网站中的页面需要验证。
我可以用网站的 web.config 文件做什么???
<location path="signalr/send" >
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="Home/pageone" >
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>-->
</system.web>
这样,我只能让pageone不需要验证,但它不适用于signalR客户端程序
有我的 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=301880
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<location path="Home/Index3" ><!--this way is working ,I can make the index3 page could be viewed with no authentication-->
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="signalr/send" > <!--this url is got by Request.Url.AbsoluteUrl in the hub class,but this way is not working-->
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="refreshhub/senditems" > <!--my hub is named as "RefreshHub" and the method the client revoked is "senditems", but this configuration is not working either-->
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<authentication mode="Forms"> <!--I give my website all page Form authentication-->
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
<httpRuntime targetFramework="4.5" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
【问题讨论】: