Wednesday, April 8, 2015

Generate Hierarchy XML using SQL Server.

Hello Friend's,

Today I have worked on generating Hierarchy XML output using SQL Server. Later I have bind this XML with TreeView.

Below is my table.


for your reference below is table creation query.

CREATE TABLE [dbo].[Ketan_Example](
[Id] [int] NOT NULL,
[Item] [nvarchar](50) NULL,
[ParentID] [int] NULL,
 CONSTRAINT [PK_Ketan_Example] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]



Now insert dummy data in table.





Create function

CREATE FUNCTION [dbo].[ketan_HierarchyNode] (@ParentID INT) RETURNS XML
BEGIN RETURN
    (SELECT Id as Value, 
            ParentID, 
            Item,
            dbo.ketan_HierarchyNode(Id)
        FROM Ketan_Example as Node 
        WHERE ParentID = @ParentID
        FOR XML Auto)
END;

GO



Create Store Procedure.

CREATE  PROCEDURE [dbo].[GetXMLforLabeling]
AS

SELECT 
Id,
        ParentID,
        Item,
        dbo.ketan_HierarchyNode(Id)
FROM    Ketan_Example
WHERE   ParentID IS NULL 
FOR     XML AUTO




All Done !!!


Now execute the Store Procedure.





Let me know if you have any question.


Friday, October 24, 2014

Could not load file or assembly 'Microsoft.Reportviewer.Winforms Version=8.0.0.0” while generating Report

Solution :- 

Application have a this error when some files which require to run report viewer are missing.
There are two important files which needs to be on production environment to run report successfully.

Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.WinForms.dll

For WebApplication Error Application needs below two dll's.
Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.WebForms.dll

To resolve this install the ReportViewer Redistributable component from one of the following locations:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21916 (Visual Studio 2005 components)

or

http://www.microsoft.com/download/en/details.aspx?id=6576 (Visual Studio 2008 components)

Other way to get this redistributable.

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\ReportViewer\ReportViewer.exe

Install this and you all set to run reportviewer.

Tuesday, December 25, 2012

How to change hasehd password if you don't know the current password using asp.net membership provide ?

Many programmers stuck into above problem. the solution is reset the password randomly and pass that into the change method.

 

MembershipUser u = Membership.GetUser();
u.ChangePassword(u.ResetPassword(), "myAwesomePassword");




Enjoy !!!

Friday, December 21, 2012

How to secure webservice in asp.net.

Hello Frd's

While working with web service in asp.net one main question that stick on my mind is how I make secure  my web service.

I am going to publish web service in public domain any one can use it after knowing web url. I found very good discussion from asp.net forum let me share with you.


Securing a web service can be achieved at many levels, it is up to you to which level you may want to do.

1) Customised Token Based:

Have a web method where user may provide his credentials. Credentials could be username and password; this is quite similar to login page of the web form application. So, once user passes his username and password system validates these credentials against the database system generates a unique token (which is generally guid) and saves this against userid ion the database. This token is returned to the user as well. So, now onwards whenever user acceses other web methods (of functional nature) this token will need to be passes along as parameter. Before actually processing the call system validates this token against the database. If it is validated user is allowed to process the web method call. Additionally, just like session in the web forms application, you may control the timeout as well. for e.g. the token may remain valid for some pre-defined time and post that whenever user tries to access any method token gets expired and user is denied the request. You may set this timeout during login web method call.

2) WSE 3.0 Authentication:  

Web Services Enhancements (WSE) is a webservice standard which provides cross-platform security for webservices. Following URL will provide a step-by-step detail on how to use WSE 3.0 for authenticating webservices with your custom user database.

http://aleemkhan.wordpress.com/2007/09/18/using-wse-30-for-web-service-authentication/

Following link describes in detail how to develop and apply authentication, authorization, and secure communication techniques to secure ASP.NET Web services and Web service messages. It describes security from the Web service perspective and shows you how to authenticate and authorize callers and how to flow security context through a Web service. It also explains, from a client-side perspective, how to call Web services with credentials and certificates to support server-side authentication.


http://msdn.microsoft.com/en-us/library/aa302390.aspx#secnetch10_authstrategies

Pass Argument when opening page from Link button/Hyperlink from gridview.


Hello,

use below code to pass argument to new opening page.

Suppose we are try to open EmpDetail page by cliking on HyperLink.

<asp:HyperLink ID="mylink" runat="server"
         NavigateUrl='<%# Eval("EmpID","EmpDetail.aspx?EmpId={0}") %>' Text='<%# Eval("EmpName") %>'>
</asp:HyperLink>


Enjoy !!!!