Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:53:52+00:00 2026-06-09T18:53:52+00:00

I am trying to deny access to a folder or resources when not logged

  • 0

I am trying to deny access to a folder or resources when not logged in (prevent leeching). In the folder I have my

Web.config: (/Media)

<?xml version="1.0"?>
<configuration>
  <system.web>
    <authorization>
      <deny users="?"/>
      <allow users="*" />
    </authorization>
  </system.web>
</configuration>

The code I am calling:

Index:

@Video.MediaPlayer(
    path: "~/Media/Tree Felling2.wmv",
    width: "600",
    height: "400",
    autoStart: false,
    playCount: 1,
    uiMode:  "full",
    stretchToFit: true,
    enableContextMenu: true,
    mute: false,
    volume: 75)

@Video.Flash(path: "~/Media/sample.swf",
             width: "80%",
             //height: "600",
             play: true,
             loop: false,
             menu:  true,
             bgColor: "red",
             quality: "medium",
             //scale: "showall",
             windowMode: "transparent")

When logged out: flash is not shown. Media player wont connect to media. ( AS EXPECTED )

When logged in: flash is shown. But media player still wont connect to media.

Where am I going wrong?..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:53:53+00:00Added an answer on June 9, 2026 at 6:53 pm

    Unfortunately this is a known bug with the Windows Media Player for FF. It will work in IE.

    The reason for this not working is pretty simple: the plugin doesn’t send the authentication cookie along with the request so it is as if you are not authenticated.

    The only way to make this work is to append the cookie value as a query string parameter to the request and then resynchronize the session on the server.

    Let’s put that into action, shall we?

    Unfortunately we cannot use the @Video.MediaPlayer helper because it doesn’t allow you to specify query string parameters, it works only with physical files (which kinda sucks). So:

    <object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" height="400" width="600" >
        <param name="URL" value="@Url.Content("~/media/test.wmv?requireAuthSync=true&token=" + Url.Encode(Request.Cookies[FormsAuthentication.FormsCookieName].Value))" />
        <param name="autoStart" value="False" />
        <param name="uiMode" value="full" />
        <param name="stretchToFit" value="True" />
        <param name="volume" value="75" />
        <embed src="@Url.Content("~/media/test.wmv?requireAuthSync=true&token=" + Url.Encode(Request.Cookies[FormsAuthentication.FormsCookieName].Value))" width="600" height="400" type="application/x-mplayer2" autoStart="False" uiMode="full" stretchToFit="True" volume="75" />
    </object>
    

    and inside Global.asax we subscribe to the Application_BeginRequest method and resync up the authentication cookie from the request:

    protected void Application_BeginRequest()
    {
        if (!string.IsNullOrEmpty(Context.Request["RequireAuthSync"]))
        {
            AuthCookieSync();
        }
    }
    
    private void AuthCookieSync()
    {
        try
        {
            string authParamName = "token";
            string authCookieName = FormsAuthentication.FormsCookieName;
    
            if (!string.IsNullOrEmpty(Context.Request[authParamName]))
            {
                UpdateCookie(authCookieName, Context.Request.QueryString[authParamName]);
            }
        }
        catch { }
    }
    
    private void UpdateCookie(string cookieName, string cookieValue)
    {
        var cookie = Context.Request.Cookies.Get(cookieName);
        if (cookie == null)
        {
            cookie = new HttpCookie(cookieName);
        }
        cookie.Value = cookieValue;
        Context.Request.Cookies.Set(cookie);
    }
    

    And that’s pretty much it. The only requirement for this to work is to be running in IIS 7 Integrated Pipeline Mode in order for all requests to go through ASP.NET, even those for .wmv files, otherwise the BeginRequest will obviously never trigger for them.

    If you are using some legacy web server (such as IIS 6.0) or running in Classic Pipeline mode and don’t want to do a wildcard mapping of all requests with ASP.NET you could put all your media files in a secure location (such as ~/App_Data) that cannot be directly accessed by users and then serve them through a controller action decorated with the [Authorize] attribute:

    [Authorize]
    public ActionResult Media(string file)
    {
        var appData = Server.MapPath("~/App_Data");
        var filename = Path.Combine(path, file);
        filename = Path.GetFullPath(filename);
        if (!filename.StartsWith(appData))
        {
            // prevent people from reading arbitrary files from your server
            throw new HttpException(403, "Forbidden");
        }
        return File(filename, "application/octet-stream");
    }
    

    and then:

    <object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" height="400" width="600" >
        <param name="URL" value="@Url.Action("media", "home", new { requireAuthSync = true, token = Request.Cookies[FormsAuthentication.FormsCookieName].Value })" />
        <param name="autoStart" value="False" />
        <param name="uiMode" value="full" />
        <param name="stretchToFit" value="True" />
        <param name="volume" value="75" />
        <embed src="@Url.Action("media", "home", new { requireAuthSync = true, token = Request.Cookies[FormsAuthentication.FormsCookieName].Value })" width="600" height="400" type="application/x-mplayer2" autoStart="False" uiMode="full" stretchToFit="True" volume="75" />
    </object>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to control access to my website with windows integrated. <?xml version=1.0?>
I have the following on my web.config <location path = WebPages/Reports> <system.web> <authorization> <deny
Hey. I need to prevent direct access to http://www.site.com/wp-content/uploads/folder/something.pdf through the browser. However the
I have a RoR web app that I'm trying to serve up with Passenger
I am trying to deny access to a sub-domain directory from people accessing directly
Basically I am trying to configure Access to a specific Folder on my shared
I have a SQL Server 2005 database that I'm trying to access as a
I'm attempting to password protect my public folder so that anyone trying to access
I'm currently trying to deny access to a specific html-document which should only be
I am trying to limit access for a page like so <location path=ArticleAdministration.aspx> <system.web>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.