Posts tagged: asp.net

Dec 03 2012

OrchardCMS is blocking Anonymous Users when accessed remotely

I have a production OrchardCMS site that is running fine.

Today I copied all of the files from that site to a local server so I could use it for staging and testing changes before deployment. One other little change I made is changed the Orchard instance to use a local full SQL instance instead of Sql CE. (Which is something I will also do in production in the next few days.)

The migration has worked fine. I can load the Orchard instance using localhost on port 2764 (the one I assigned) and it works perfectly ... exactly as on production.

I setup port forwarding on my router to connect to this staging/testing server when connecting on port 2764. (And also created an inbound rule on the local server).

When I access the site on that port from a remote computer, it loads the CONTENT but does not fetch any of the files (CSS, JS, etc.) So I see content but it is raw unformatted html.

I loaded the page in fiddler and it shows a header like this for the sessions...

HTTP/1.1 302 Found
Location: /Users/Account/AccessDenied?ReturnUrl=%2fThemes%2fBootstrap%2fStyles%2fbootstrap.min.css
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 03 Dec 2012 04:38:01 GMT
Content-Length: 205

and then ...

GET /Users/Account/AccessDenied?ReturnUrl=%2fThemes%2fBootstrap%2fStyles%2fbootstrap.min.css HTTP/1.1
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 03 Dec 2012 04:38:01 GMT
Content-Length: 2179

If I login to the site (I can still see the login button and subsequent login page) I am successfully logged in and then the website performs perfectly normally...until I log out again.

So the bottom line...anonymous users can see content but OrchardCMS (or IIS ... or both?) will not fetch any of the files it seems.

Any ideas on the cause of this? Thanks for your help.

Seth

Oct 25 2012

How do I call an Index action and conditionally pass it a value in an ASP.NET MVC app

        <p>I have an index action on a controller as follows...</p>
public ActionResult Index(string errorMsg = "")
   {
      //do stuff
      ViewBag.ErrorMsg=erorMsg;

      return View();
   }

I have another action that is an http post for Index.

When there is something wrong I want to reload the Index page and show the error...

I have my view already conditionally showing errorMsg. But I cannot figure out how to call Index and pass in the error string?

Oct 25 2012

How do I call an Index action and conditionally pass it a value in an ASP.NET MVC app

I have an index action on a controller as follows...

public ActionResult Index(string errorMsg = "")
   {
      //do stuff
      ViewBag.ErrorMsg=erorMsg;

      return View();
   }

I have another action that is an http post for Index.

When there is something wrong I want to reload the Index page and show the error...

I have my view already conditionally showing errorMsg. But I cannot figure out how to call Index and pass in the error string?

Jun 08 2012

What are the legal risks if any of using a GPL’ed Web Application Framework/CMS?

        <p>Am I correct in saying that using a GPL'ed web application framework such as Composite C1 would NOT obligate a company to share the source code we write against said framework?  </p>

That is the purpose of the AGPL, am I correct?

Does this also apply to Javascript frameworks like KendoUI?

The GPL would require any changes that we make to the framework be made available to others if we were to offer it for download.

In other words, merely loading a web sites content into my browser is not "conveying" or "distributing" that software.

I have been arguing that we should avoid GPL web frameworks and now after researching I am pretty sure I am wrong but wanted to get other opinions?

Seth

May 24 2012

What is the best way to verify cookies are enabled for html 5 (mobile) website using asp.net mvc 3

I know that similar questions have been asked here but I am nevertheless having trouble getting it to work.

I am writing an html 5 website using ASP.NET MVC 3 that is targeted to mobile devices.

I had previously asked another question about how to store and retrieve expensive data and decided to go with Session variables.

I finished the app and started internal testing and all was well until we realized that the web site is not working on some iPhones. After researching I came to realize that Session variables depend on cookies and that some iPhones ship with cookies disabled by default.

Until I come up with a better solution, I want to check to see if cookies are enabled and redirect to an error page.

I was hoping that ALL of the code to do this could be written in a base controller but I could not figure out how to do it. So instead I put the following code into the base controller...

protected void WriteCookie()
{
    Response.Cookies.Add(new HttpCookie("cookie_test"));
}

protected bool CookieCheck()
{
    return (Request.Cookies["cookie_test"] != null);
}

Then in a home controller I am calling the WriteCookie method before loading the view. The view itself has javascript that is redirecting to one of two controllers / actions. The controller / view that will usually be called (because html 5 could not resolve the location) is the ChangeLocation / Index controller/action. In there I have the following code...

if (!CookieCheck())
{
    RedirectToAction("CookieRequired", "Error");
}

Even with cookies disabled it is not redirecting to the above error page.

So what I am looking for is a best practices approach for solving this problem with a fairly complete code sample.

My home controller is pretty much ALWAYS redirecting to another page (in the javascript not the controller). I have a total of about 4 controllers with a total of about 6 actions.

My ideal would be to solve this problem completely in the base controller. If not that then I would love for it to work no matter what valid URL is typed (in other words, even if the web app is not entered through Home / Index). If not that then at least I want what I have shown in my code to work (set the cookie in Home / Index and check for it in the other controller / actions) and work even if the redirect is happening in a controller.

May 06 2012

How do I include ul tags inside of a razor code block?

How come the following code works fine...

        <ul class="searchList">
            @if (Model.Count() > 0)
            {
                foreach (var partner in Model)
                {
                    <li>
                        @Html.ActionLink(@partner.Name, "Details", "Partner", new { id = partner.AID }, null)<br />
                        @partner.Street<br />
                        @partner.CityStateZip<br />
                        @if(!string.IsNullOrEmpty(partner.Phone))
                            {
                               @partner.Phone<br />
                            }
                        @(partner.Distance) miles<br />
                    </li>
                }
            }
        </ul>

But this code does not work fine...

            @if (Model.Count() > 0)
            {
                <ul class="searchList">

                        foreach (var partner in Model)
                        {
                            <li>
                                @Html.ActionLink(@partner.Name, "Details", "Partner", new { id = partner.AID }, null)<br />
                                @partner.Street<br />
                                @partner.CityStateZip<br />
                                @if(!string.IsNullOrEmpty(partner.Phone))
                                    {
                                       @partner.Phone<br />
                                    }
                                @(partner.Distance) miles<br />
                            </li>
                        }

                </ul>
             } 

The second error one returns the following error...

Compiler Error Message: CS0103: The name 'partner' does not exist in the current context.

I am finding the code mixing rules of Razor to be difficult to follow. Any link that gives the canonical explanation will be appreciated.

Seth

May 04 2012

In Mvc 3 razor view what is the best way to conditionally render html based on Nulls in the model

This is I am sure an easy question but I am having trouble figuring this out.

I want to do something like this....

@(string.IsNullOrEmpty(Model.CustomerUrl) ? "" : <a href="@Model.CustomerUrl">Click me</a>)

This snippet doesn't work.

The mixing of the html with the razor syntax and the inclusion of quotes in the attributes of the tags is making it hard to figure out.

I love razor except figuring out this kind of stuff is really tripping me up.

I would love to just not render the following at all if the CustomerUrl was null or empty...

<p class="customerLink links"><a href="@Model.CustomerUrl">@Model.CustomerName</a></p>

EDIT
This is still not working for me...thanks for the suggestion though.

My issue is that the above code is ALREADY in a Razor Code Block. Here is my actual code that I cannot figure out...

EDIT NUMBER TWO - THE following code is now working

    @if (Model.Count() > 0)
    {
        foreach (var partner in Model)
        {
            <li>
                @Html.ActionLink(@partner.CustomerName, "Details", "Customer", new { id = Customer.AID }, null)<br />
                @partner.Street<br />
//this is what i cannot figure out!!
                @if(!string.IsNullOrEmpty(partner.Phone))
                    {
                        @partner.Phone@:<br />
                    }
                @partner.Distance<br />
            </li>
        }
    }

I preceded the nested block (the if) with the @ symbol. Then the markup
I had to delimit with @: Then it worked.

It seems yesterday when I tried to use a nested razor code block I got a compiler error BECAUSE I preceded it with an @. So now I am more confused than ever.

In fact...if I tried to surround my @partner.Phone with quotes like this... "@partner.Phone"@:</ br> I get another compiler error. Razor is great when it works but when it doesn't it is very confusing.

Seth

May 02 2012

How do you pass "expensive" data from page to page using ASP.NET MVC 3?

I am doing my first ASP.NET MVC project. (In fact, for the record, this is my first production website of any kind).

This is a mobile web page targeting HTML 5.

This page looks up some "expensive" information. First it uses the html 5 geocoding feature to get the customers latlong from their browser.

I pass that information to a controller. That controller fills in the City and State (into a location model) using the Google Maps API and then uses it in the view.

So this data is expensive in two ways, first it takes time to look it up and second, in the case of the Google API, it is literally not free in that Google limits the number of calls that can be made per day.

I understand that MVC is designed to "embrace" the web including the fact that http is a stateless protocol.

Nevertheless, I would like to avoid having to fetch this expensive data on every page load for every endpoint that needs it. Furthermore, one other piece of state that I would like to keep track is the fact that the data has already been fetched.

What is the best way / best practice for achieving this on an MVC 3 web application? Since my model for location has 4 data point (lat long city state) and there is a fifth data point (data retrieved) I would really like to avoid using querystrings to do this or a route for all of those data points?

I am sure this is a common need but I honestly don't know how to tackle it. Any help will be appreciated.

Seth

Oct 19 2011

Are there other .NET based Content Management Systems (CMS) beside DotNetNuke that support multiple sites with one install?

I know that there are a LOT of questions on SO about CMSs based on .NET but I have just one specific question.

I know that DotNetNuke supports multiple site creation on one installation. Of the other wellknown .Net CMSs...

N2CMS Composite C1 Umbraco Orchard AxCMS

...do any of them support this feature out of the box (or with relative ease)?

BTW, if you know of some low-cost non-free CMSs that would support this feature don't hesitate to give them a mention (as long as they are built on the Microsoft stack.)

EDIT Just learned that this feature is called multi-tenancy...thanks David.

Seth

Oct 19 2011

Are there other .NET based Content Management Systems (CMS) beside DotNetNuke that support multiple sites with one install? [migrated]

I know that there are a LOT of questions on SO about CMSs based on .NET but I have just one specific question.

I know that DotNetNuke supports multiple site creation on one installation. Of the other wellknown .Net CMSs...

N2CMS Composite C1 Umbraco Orchard AxCMS

...do any of them support this feature out of the box (or with relative ease)?

BTW, if you know of some low-cost non-free CMSs that would support this feature don't hesitate to give them a mention (as long as they are built on the Microsoft stack.)

EDIT Just learned that this feature is called multi-tenancy...thanks David. Thanks for your answers. Can anyone give clarity on whether N2CMS, Composite, or AxCMS support multi-tenancy.

Seth