.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Razor + PassThrough or AD Auth

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

Not sure if this can be achieved with Razor syntax (would be grouse if it could be) but I want to deploy just a simple application with Windows authentication. I would put the application on IIS on my '08 R2 server (with AD) but I guess I want to know if we can use WebSecurity or something like that to get the Windows session username and set it as a var?

Cheers, Aaron

View Complete Post

More Related Resource Links

Sending a File Using Email Helper in WebPages/Razor


Note: This is particularly with respect to Email Helper in WebPages/Razor. Please don't post links using System.Net.Mail object.

Following this tutorial: http://www.asp.net/webmatrix/tutorials/9-adding-email-to-your-website

Under "Sending a File Using Email" section what exactly is the code trying to do.

1: The SendFile.cshtml does not have any option to select file.

2: ProcessFile.cshtml is running fine. I am getting the email but no attachement.

I tried changing fileAttachment input to type="file" but not file is being sent to my email. I just get the message send in body.

Question: How exactly this file attachment works using Email Helper in WebPages.

How to configure IIS 7.0 for ASP.NET Web Pages Razor


I'm working on a blog framework using ASP.NET Web Pages with Razor Syntax and I'm having some trouble with URL rewrites. My server is a Windows Server 2008, which runs IIS 7.0. WebMatrix is already installed on the server and .cshtml pages runs without problems, as long as they are named "index.cshtml" I don't have to supply the extension.

What does not work, is when I have URLs that does not correspond to physical files, e.g. website/post/why where the only physical file I have is post.cshtml. With IIS Express, the post.cshtml file is execute but on IIS 7.0 I get a 404 error.

Should I install the URL Rewrite for IIS 7.0? What configuration changes is required?

Razor and Visual Studio Intellisense



I am using VS 2010 with MVC3 and Razor view engine but on the views when I write @... I never have intellisense.

Do I need to do something?



Using Dynamic Property inside Html Helper with Razor fires an error



I have the following with Razor:

@Html.GoogleAjax(View.GoogleAjaxKey, new String[,] { { "jquery", "1.4.2" } })

And the I get a strange error:

  'System.Web.Mvc.HtmlHelper<object>' has no applicable method named 'GoogleAjax' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

What is strange is that it works fine using:

@Html.GoogleAjax("123", new String[,] { { "jquery", "1.4.2" } })

I tried the following code line:


And the key is displayed just fine so the problem is how I use the value of @View.GoogleAjaxKey into Html.GoogleAjax.

Do I need to change something on my Html Helper? Here it is:

    public static MvcHtmlString GoogleAjax(this HtmlHelper helper, String key, String[,] libraries) {


Encoding Problems in Razor



On my projects I am using SquisIt Framework and I have the following on page head:


      .Render("~/Styles/FlyOnDreams.FlyOnPages.Core.min.css")) %>

This is working. However when I use Razor view engine I am using the following:


Razor and ResolveUrl



I have the following:

<script type="text/javascript">
  var root = '<%=ResolveUrl("~/")%>';  

And I am trying to do the same with Razor:

  <script type="text/javascript">
    var root = '@ResolveUrl("~/")';  

But I keep having the error:

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

What am I doing wrong?



<script type="text/javascript">

Razor View Engine and Add Namespace in Web.Config Problem



I am working on a MVC project with Razor view engine and I have the following:


This only works if I have on the same view the following:

  @using SquishIt.Framework;

However, on my Web.Config I have the following:


      <!-- Namespaces -->
        <add namespace="System"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="Microsoft.Web.Mvc"/>
        <add namespace="SquishIt.Framework"/>


So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

ASP.NET MVC3 Areas and Razor views produce errors?


The view at '~/Areas/SomeArea/Views/List/Index.cshtml' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl.

The project structure is pretty much default. There is one area called SomeArea. It has a single controller called List. It does nothing except:

public ActionResult Index()
    return View("~/Areas/SomeArea/Views/List/Index.cshtml");

The view looks like:

@inherits System.Web.Mvc.WebViewPage<dynamic>
    View.Title = "Index";
    LayoutPage = "~/Views/Shared/_Layout.cshtml";


I have tried emptying the entire file part by part and nothing seems to help. If I create a controller and view outside the area it works just fine. If I create an aspx view it works fine as well. Is it possible the default razor view engine doesn't support areas at this time?

The areas are registered too.

public static void RegisterRoutes(RouteCollection routes)
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters

Razor. Conditional Rendering.



I am using Razor and I need to display a String or the view property value on the following condition:

@if(String.IsNullOrEmpty(View.Title)) { @("Default Title") } else { @View.Title }

This is working. But can I make this simpler?

I tried the following:

@String.IsNullOrEmpty(View.Title) ? @("Default Title") : @View.Title

This is not working ...



.NET BC : A Lap around WebMatrix; With a dash of Razor



Last night most of the DotNetnuke team and I traveled into Burnaby, to the BCIT campus where I gave a real quick (1 hour) presentation on the WebMatrix Beta, and Razor Syntax.

I was happy to see that we had over 60 people attend.  It was awesome to see the turn out on a hot summer evening. 

Download the Slide Deck

There were a number of questions which came up, I will try to remember them all here.


Working with Data - the db.Query() execution, can it be parametrized?

var db = Database.OpenFile("SmallBakery.sdf");
var selectQueryString = "SELECT * FROM Products ORDER BY Name";
@foreach (var row in db.Query(selectQueryString)){