Feeds:
Posts
Comments

Archive for the ‘ASP.NET’ Category

ASP.NET doesn’t make shadow copies of unmanaged DLLs such as libsodium.dll and libsodium-64.dll.

Sodium.dll (the managed code) tries to load the DLLs from either the same directory as the shadow copy of Sodium.dll (which is not going to work) – or some where in the PATH environment variable’s directories.

Solution 1:

add the AppDomain \Bin directory to the path before calling any Sodium code:

string
path = Environment.GetEnvironmentVariable("PATH");

string binDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “Bin”);
Environment.SetEnvironmentVariable(“PATH”, path + “;” + binDir);

Add the above code in Application_Start method of my Global.asax.

This solution works when u r running locally. but when you deploy in azure it wont work.

Solution 2:

You have to install Visual C++ Redistributable for Visual Studio 2015 (13 Mb)
https://www.microsoft.com/en-us/download/details.aspx?id=48145

I tried with this approach. but not completely successful.

Solution 3:

Add your bin folder path in environmental variables “path”. or Copy Sodium.dll  & libsodium-64.dll to your C:\Windows\System32 folder.

Solution 4:
Since we know that the binary is available on site root, we can either add site root path to PATH environment variable (binary in question along with all its dependencies are available under SiteRoot directory) or we can just disable Shadow Copying by adding following web.coinfg entry:

<system.web>
	<hostingEnvironment shadowCopyBinAssemblies="false"/>
</system.web>

AppDomain will now consider SiteRoot as it’s location and modifications to files under SiteRoot would cause application to crash and not a good idea on production environments. But since I always deploy a full CSPKG to production environment and never touch the files on production environment, I am good with this change.

Read Full Post »

The debate still rages on…no, not PC or Mac, but should my application be thick client or thin client. Thick client applications are those that require an application be installed on your desktop. Thin client applications are those that utilize the Web browser in order to run. So, which is right for you and what are the pros and cons of each?

Thin client:

Pros:
-Run from any Web browser
-Does not require installation
-Can be hosted remotely for security reasons
-Implementation and maintenance from one centralized location, the application server.

Cons:
-Application has to be coded for multiple types of Web Browsers
-Requires the application be run from an application server (For Example:Windows Server running IIS)
-Reqires network hardware and/or and Internet connection

Thick client:

Pros:
-Does not require an application server
-Does not require network hardware or Internet service (Unless a database must be accessed)

Cons:
-Must be installed locally on users computer
-Implementation and Maintenance nightmare

Depending on what your needs are is really the deciding factor. If you have one computer, and only need the application on that computer, then Thick Client is the quickest way and most efficient way to go. However, if others need access to the application, at multiple locations, then an Internet-based Thin Client application is right for you.

Algorithm Intelligence can help you make this decision and give your company the application it needs. Speak up and let us know what you think about this long-time debated issue.

Read Full Post »

Asp.net membership provider is a new feature of Asp.net 2005. We can create membership tables using aspnet_regsql.exe in vs command prompt. This blog describes how to create aspnetdb databse in your Sqlexpress

ASP.NET Membership

ASP.NET membership is a built in way to validate and store user credentials.And Asp.Net membership helps in user authentication in websites. We can implememt membershipprovider by Asp.net Forms authentication and Login control.

Purppose Of Membeship provider

1. Create new user with username and password.

2. Storing membership information in Sql Server,Active directory etc.

3.Authentication of users. By using ASP.NET login control,ASp.NET usercreation wizard etc implement complete authentication system.

4.Fascilitate role management etc

The database used to access membership database is normaly created with name ASPNETDB.MDF. Here is how to install ASPNETDB database

Creating ASPNETDB DATABASE in your SQLEXPRESS
ASPNETDB.MDF is membership provider database and is used for storing and retrieving
membership data from database and here we are going to see how to create membership provider database . The command used to create Aspnetdb.mdf is ASPNET_RegSQL.EXE

1.Start->Programs->Microsoft visual studio 2005->visual studio tools->Visual Studio 2005 command prompt. Type ASPNET_RegSQL.EXE in the visual Studio 2005 command prompt

2. A wizard with the heading ” Welcome To The Asp.Net Sql Server Wizard ” will be displayed. Here need to click Next

3. Next a wizard with ” Select Setup Option ” will displayed. Now we need to select setup option “Configure sql server for application purpose is default”. Select which one you wants and next.

4. A window with ” Select Sql Server Database ” Will be shown Now we need to select our sql server database. Here needs to set server, authentication type and database.
If select the default name”aspnetDb.mdf” will be selected. If you wants to modify existing database select that database.

5.Now A confirm will be displayed with heading “Confirm your Settings”. Now check servername and database name and click next.

6. A window with ” The database Has Been Created Or Modified ” Will displayed. Now click Finish

These all are how to create an asp.net membership database on sql Server 2005 database

Read Full Post »

<script>
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split(“&”);
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split(“=”);
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}
</script>

<script>
  alert( getQueryVariable(“QueryString”) );
</script>

Read Full Post »

iframe 100% height

So <iframe height="100%"> doesn’t make an iframe fill all the remaining portion of a window like you might expect. I found several places where people showed how they got it to resize with javascript, but those didn’t work for me. The DOM properties that they used were frequently the “page” height (e.g. 250px for a short content page, 1300px for a tall page that has scrolling) or something else wrong. Here is what works for me (in Firefox 2 and IE 7) to make an iframe be as high as possible without causing the main window to have scrolling:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”&gt;
<html>
<head>Test Page</head>
<body>
<h1>Check out the cool page below</h1>
<p><a href=”/”>Go back home</a></p>

<iframe id=”frame” src=”http://google.com/&#8221; width=”100%” frameborder=”0″ marginheight=”0″ marginwidth=”0″></iframe>
<script type=”text/javascript”>
function resizeIframe() {
    var height = document.documentElement.clientHeight;
    height -= document.getElementById(‘frame’).offsetTop;
   
    // not sure how to get this dynamically
    height -= 20; /* whatever you set your body bottom margin/padding to be */
   
    document.getElementById(‘frame’).style.height = height +”px”;
   
};
document.getElementById(‘frame’).onload = resizeIframe;
window.onresize = resizeIframe;
</script>

Read Full Post »

In no particular order, here are the top ten things I’ve learned to pay attention to when dealing with production ASP.NET applications.  Hopefully they will help you save you some time and headaches.  As always, your thoughts and additions are welcome.

1.  Generate new encryption keys

When moving an application to production for the first time it is a good idea to generate new encryption keys.  This includes the machine validation key and decryption key as well as any other custom keys your application may be using.  There is an article on CodeProject that talks about generating machineKeys specifically that should be helpful with this.

2.  Encrypt sensitive sections of your web.config

This includes both the connection string and machine key sections.  See Scott Guthrie’s post for some good references.  Note that if your application runs in a clustered environment you will need to share a custom key using the RSA provider as described in an MSDN article.

3.  Use trusted SQL connections

Both Barry Dorrans and Alex Chang have articles which discuss this in detail.

4.  Set retail=”true” in your machine.config

    <configuration>
    <system.web>
    <deployment retail=“true”/>
    </system.web>
    </configuration>This will kill three birds with one stone.  It will force the ‘debug’ flag in the web.config to be false,  it will disable page output tracing, and  it will force the custom error page to be shown to remote users rather than the actual exception or error message.  For more information you can read Scott Guthrie’s post or the MSDN reference.

5.  Create a new application pool for your site

When setting up your new site for the first time do not share an existing application pool.  Create a new application pool which will be used by only by the new web application.

6.  Set the memory limit for your application pool

When creating the application pool, specifically set the memory limit rather than the time limit which is set by default.  Asp.net has a good whitepaper which explains the value of this:

By default IIS 6.0 does not set a limit on the amount of memory that IIS is allowed to use. ASP.NET’s Cache feature relies on a limitation of memory so the Cache can proactively remove unused items from memory.

It is recommended that you configure the memory recycling feature of IIS 6.0.

7.  Create and appropriately use an app_Offline.htm file

There are many benefits to using this file.  It provides an easy way to take your application offline in a somewhat user friendly way (you can at least have a pretty explanation) while fixing critical issues or pushing a major update.  It also forces an application restart in case you forget to do this for a deployment.  Once again, ScottGu is the best source for more information on this.

8.  Develop a repeatable deployment process and automate it

It is way too easy to make mistakes when deploying any type of software.  This is especially the case with software that uses configuration files that may be different between the development, staging, or production environments.  I would argue that the process you come up with is not nearly as important as it being easily repeatable and automated.  You can fine tune the process as needed, but you don’t want a simple typo to bring a site down.

9.  Build and reference release versions of all assemblies

In addition to making sure ASP.NET is not configured in debug mode, also make sure that your assemblies are not debug assemblies.  There are of course exceptions if you are trying to solve a unique issue in your production environment … but in most cases you should always deploy with release builds for all assemblies.

10.  Load test

This goes without saying.  Inevitably, good load testing will uncover threading and memory issues not otherwise considered.

Read Full Post »

We will use an ActiveX Object from the Scripting.FileSystemObject library to read and write files from JavaScript, which knows how to handle files. The parameter of the OpenTextFile function can be (read = 1, write = 2, append = 8).And here are the scripts:

Reading a File:

function ReadFile()
{

var FileOpener = new ActiveXObject(”Scripting.FileSystemObject”);
var FilePointer = FileOpener.OpenTextFile(”C:\\siva.txt”, 1, true);
FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines
alert(FileContents);
FilePointer.Close();
}
Writing to File:

function WriteFile
{

var FileOpener = new ActiveXObject(”Scripting.FileSystemObject”);
var FilePointer = FileOpener.OpenTextFile(”C:\\siva.txt”, 8, true);
FilePointer.WriteLine(”I m a good boy”);
FilePointer.Close();
}

Note:
Go to Tools >> Internet Options >> Security, add page to Trusted sites >> then go to Custom level… and look for Initialize and script ActiveX controls. Enable it and restart the Internet Explorer.

Read Full Post »

Declare a dropdown as usual in the master page

<asp:DropDownList ID=”drpLanguage” runat=”server” AutoPostBack=”True”  OnSelectedIndexChanged=”drpLanguage_SelectedIndexChanged” >
    <asp:ListItem  Value=”en-US” Selected=True>English</asp:ListItem>
    <asp:ListItem  Value=”de-DE”>German</asp:ListItem>
</asp:DropDownList>

Add Dropdown ClientId to the Session Variable on Master Page init event

protected void Page_Init(object sender, EventArgs e)
 {
    Session[“DDLUniqueID”] = drpLanguage.UniqueID;
 }

Add selected language value to the session

protected void drpLanguage_SelectedIndexChanged(object sender, EventArgs e)
 {

    Session[“Language”] = drpLanguage.SelectedItem.Value.ToString();
     
 }

To keep Dropdown selected value in the page transfers, Use the following logic to select dropdown value from the session.

protected void Page_Load(object sender, EventArgs e)
 {    
     if (!IsPostBack)
        {
            if (Session[“Language”] != null)
            {
                drpLanguage.ClearSelection();
                drpLanguage.Items.FindByValue(Session[“Language”].ToString()).Selected = true;
            }
            else
            {
                drpLanguage.ClearSelection();
                drpLanguage.Items.FindByValue(“en-US”).Selected = true;
            }
        }
 }

Create a base page. All webpages will inherit from the base page.
Add the the following methods the Base page.

protected override void InitializeCulture()
 {
            string selectedCulture = string.Empty;
            if (Session[“DDLUniqueID”] != null) // first time this will be null
            {
                string id = Session[“DDLUniqueID”].ToString();
                selectedCulture = Request.Form[id]; // this will get the selected value.
                SetCulture(selectedCulture);
            }         
            else
            {
                SetCulture(“en-US”);  //Default English.
            }
   
        base.InitializeCulture();
 }

private void SetCulture(string strLan)
 {             
        System.Globalization.CultureInfo lang = new System.Globalization.CultureInfo(strLan);
        System.Threading.Thread.CurrentThread.CurrentCulture = lang;
        System.Threading.Thread.CurrentThread.CurrentUICulture = lang;
 }

 
 
Notice, there is absolutely no code in any of the content pages. Thats it ten lines of code and we are done for the whole site. This is not complete code, just a tip and trick of using master page and the base page globalize code.

Read Full Post »