asp.net捆绑包请求的会话访问禁用
我在我的应用程序中使用asp.net和MVC4,也在css和js文件中使用捆绑 当我查看跟踪文件时,我发现所有的捆绑请求都在使用session。i、 例如,所有捆绑请求都通过sessionstatemodule传递 我的轨迹如下所示asp.net捆绑包请求的会话访问禁用,asp.net,.net,asp.net-mvc,bundling-and-minification,Asp.net,.net,Asp.net Mvc,Bundling And Minification,我在我的应用程序中使用asp.net和MVC4,也在css和js文件中使用捆绑 当我查看跟踪文件时,我发现所有的捆绑请求都在使用session。i、 例如,所有捆绑请求都通过sessionstatemodule传递 我的轨迹如下所示 155. NOTIFY_MODULE_START ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="false" 06:59:43.480 156. A
155. NOTIFY_MODULE_START ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="false" 06:59:43.480
156. AspNetPipelineEnter Data1="System.Web.SessionState.SessionStateModule" 06:59:43.480
157. AspNetSessionDataBegin 06:59:43.480
158. AspNetSessionDataEnd 06:59:43.996
159. AspNetPipelineLeave Data1="System.Web.SessionState.SessionStateModule" 06:59:43.996
160. NOTIFY_MODULE_COMPLETION ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="false", CompletionBytes="0", ErrorCode="The operation completed successfully. (0x0)" 06:59:43.996
161. NOTIFY_MODULE_END ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 06:59:43.996
我想我的捆绑请求不需要会话访问。如何禁用捆绑请求的会话访问?如果我正确理解您的问题,您希望禁用静态资源的会话状态。为此,您可以做两件事: 1) 为
控制器禁用会话状态
为此,您需要导入System.Web.SessionState
命名空间,然后使用以下代码行装饰控制器:
[SessioState(SessionStateBehavior.Disabled)
public class HomeController: Controller
{
}
有关更多信息,请访问以下链接:
2) 创建静态资源
IIS设置:
在inetpub目录中创建两个网站
www.domain.com//主站点
static.domain.com//Foe静态资源
现在将它们指向相同的物理目录,即
C:\inetpub\www.domain.com
将domain.com重定向到www.domain.com
将任何domain.com请求重定向到www.domain.com
因此,任何domain.com请求都必须重定向到www.domain.com
因为domain.com的cookie集也将由所有子系统共享
域包括static.domain.com,因此这是非常重要的步骤
**代码更改**
在web.config文件中添加以下代码:
<appSettings>
<add key="StaticSiteName" value="static.domain.com"/>
<add key="StaticDomain" value="http://static.domain.com"/>
<add key="MainDomain" value="http://www.domain.com"/>
</appSettings>
}
添加扩展方法
public static class Extensions
{
public static string StaticContent(this UrlHelper url, string contentPath)
{
string strStaticDomain = ConfigurationManager.AppSettings["StaticDomain"];
return contentPath.Replace("~", strStaticDomain);
}
}
现在从视图中使用@Url.StaticContent()
,这样它将使用static.domain.com呈现静态资源Url,无论它是图像、脚本、CSS或捆绑包,还是我们希望引用cookieless域的任何位置。例如
<link href="@Url.StaticContent("~/Content/Site.css")" rel="Stylesheet" />
<script src="@Url.StaticContent("~/Scripts/jquery-1.7.1.js")" type="text/javascript"></script>
<script src="@Url.StaticContent("~/bundles/jquery")" type="text/javascript"></script>
<img src="@Url.StaticContent("~/Images/heroAccent.png")" alt="" />
由于文章相当大,请访问以下链接以获取完整信息:
希望这能帮助你实现你的目标
<link href="@Url.StaticContent("~/Content/Site.css")" rel="Stylesheet" />
<script src="@Url.StaticContent("~/Scripts/jquery-1.7.1.js")" type="text/javascript"></script>
<script src="@Url.StaticContent("~/bundles/jquery")" type="text/javascript"></script>
<img src="@Url.StaticContent("~/Images/heroAccent.png")" alt="" />